home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 2 / BBS in a box - Trilogy II.iso / AMUG Info / Apple / MacsBug 6.2.2 / dcmds / Pascal Samples / Echo.p next >
Encoding:
Text File  |  1991-11-19  |  2.3 KB  |  92 lines  |  [TEXT/MPS ]

  1. UNIT Echo;
  2.  
  3. (* The following MPW commands will build the dcmd and copy it to the
  4.    "Debugger Prefs" file in the System folder. The dcmd's name in
  5.          MacsBug will be the name of the file built by the Linker.
  6.  
  7.         Pascal Echo.p
  8.         Link dcmdGlue.a.o Echo.p.o {Libraries}Runtime.o {PLibraries}PasLib.o -o Echo
  9.         BuildDcmd Echo 101
  10.                     Echo 'include "Echo";'            |            Rez -a -o "{systemFolder}Debugger Prefs"
  11. *)
  12.  
  13. {$R-}
  14.  
  15. INTERFACE
  16.  
  17.         USES MemTypes, dcmd;
  18.         
  19.   { Public declaration for dcmdGlue. Must be in every dcmd. The name cannot be changed. }
  20.         PROCEDURE CommandEntry (paramPtr: dcmdBlockPtr);
  21.  
  22.  
  23. IMPLEMENTATION
  24.  
  25. CONST CR = $0D;
  26.  
  27.  
  28. PROCEDURE NumberToHex (number: LONGINT; VAR hex: Str255);
  29. VAR digits: Str255;
  30.     n: INTEGER;
  31. BEGIN
  32.   digits := '0123456789ABCDEF';
  33.         hex    := '00000000';
  34.         FOR n := 8 DOWNTO 1 DO
  35.           BEGIN
  36.                 hex[n] := digits[1 + (number MOD 16)];
  37.                 number := number DIV 16;
  38.                 END;
  39. END;
  40.  
  41.  
  42. PROCEDURE CommandEntry (paramPtr: DCmdBlockPtr);
  43. VAR pos:   INTEGER;
  44.     ch:    CHAR;
  45.                 value: LONGINT;
  46.                 ok:    BOOLEAN;
  47.                 str:   Str255;
  48. BEGIN
  49.   IF paramPtr^.request = dcmdInit THEN
  50.           BEGIN { The dcmd gets called once when loaded to init itself }
  51.                 END
  52.         ELSE
  53.   IF paramPtr^.request = dcmdDoIt THEN
  54.           BEGIN { Do the command's normal function }
  55.                 dcmdDrawLine ('Echoing parameters');
  56.  
  57.     REPEAT
  58.       { Save the position so we can rewind if we get an error }
  59.                   pos := dcmdGetPosition;
  60.                         ch  := dcmdPeekAtNextChar;
  61.                         IF ch IN ['A'..'Z', 'a'..'z'] THEN
  62.                                 BEGIN { Get the parameter as a text string }
  63.                                 ch := dcmdGetNextParameter (str);
  64.                                 dcmdDrawLine (str);
  65.                                 END
  66.                         ELSE
  67.                                 BEGIN { Get the parameter as a 32 bit value }
  68.                                 ch := dcmdGetNextExpression (value, ok);
  69.                                 IF ok THEN
  70.                                         BEGIN { The expression was parsed correctly }
  71.                                         NumberToHex  (value, str);
  72.                                         dcmdDrawLine (str);
  73.                                         END
  74.                                 ELSE
  75.                                   BEGIN { The expression contained an error. Get it as a string }
  76.                                         dcmdSetPosition (pos);
  77.                                   ch := dcmdGetNextParameter (str);
  78.                                   dcmdDrawLine (str);
  79.                                         END;
  80.                                 END;
  81.                 UNTIL ch = CHR(CR);
  82.                 END
  83.         ELSE
  84.   IF paramPtr^.request = dcmdHelp THEN
  85.           BEGIN { Display the command's help information }
  86.                 dcmdDrawLine ('ECHO [params...]');
  87.                 dcmdDrawLine ('   Echo the command line parameters');
  88.                 END;
  89. END;
  90.  
  91. END.
  92.